﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using StuMngVan.Dals;
using StuMngVan.Entities;

namespace StuMngVan
{
    public partial class FormCourse : Form
    {
        public FormCourse()
        {
            InitializeComponent();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            string sTxtname = txtName.Text;
            List<Course> courses = Dal4Course.SearchAllCourses(sTxtname);
            gvCourses.DataSource = courses;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            FormAddCourse formAddCourse = new FormAddCourse();
            formAddCourse.ShowDialog();
            btnSearch.PerformClick();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            Course courseSelected = gvCourses.SelectedRows[0].DataBoundItem as Course;
            Dal4Course.DeleteCourse(courseSelected);
            MessageBox.Show(string.Format("删除课程{0}成功", courseSelected.Name));
            btnSearch.PerformClick();
        }

        private void FormCourse_Load(object sender, EventArgs e)
        {

        }
    }
}
